package com.accesshollywood.grfxOrdering.panels;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.UIManager;

import org.jdesktop.swingx.JXCollapsiblePane;
import org.jdesktop.swingx.JXPanel;

public class CollapsiblePanel extends JXPanel {
	private JButton		btnFoldUp;
	JXPanel				headerPanel;
	JXCollapsiblePane	foldUpPanel;

	public CollapsiblePanel(JXPanel headerPanel, JXCollapsiblePane foldUpPanel) {
		super();
		this.headerPanel = headerPanel;
		this.foldUpPanel = foldUpPanel;

		this.setLayout(new BorderLayout());

		headerPanel.setAlignmentX(LEFT_ALIGNMENT);
		foldUpPanel.setAlignmentX(LEFT_ALIGNMENT);

		addFoldUpCheck();

		add(headerPanel, BorderLayout.NORTH);
		add(foldUpPanel, BorderLayout.SOUTH);
	}

	public void addFoldUpCheck() {
		btnFoldUp = new JButton();// ("");

		Action toggleAction = foldUpPanel.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION);
		btnFoldUp.setAction(toggleAction);
		btnFoldUp.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		toggleAction.putValue(JXCollapsiblePane.COLLAPSE_ICON, UIManager.getIcon("Tree.expandedIcon"));
		toggleAction.putValue(JXCollapsiblePane.EXPAND_ICON, UIManager.getIcon("Tree.collapsedIcon"));

		btnFoldUp.setText("");
		btnFoldUp.setOpaque(false);
		btnFoldUp.setContentAreaFilled(false);
		btnFoldUp.setBorderPainted(false);

		btnFoldUp.setMaximumSize(new Dimension(20, 20));
		btnFoldUp.setMinimumSize(new Dimension(20, 20));
		btnFoldUp.setPreferredSize(new Dimension(20, 20));
		btnFoldUp.setAlignmentX(LEFT_ALIGNMENT);

		headerPanel.add(btnFoldUp, 0);

		btnFoldUp.doClick();
	}
}
